package com.kerrykidz.system.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kerrykidz.membership.dao.mapper.CusClassImpDtlEntityMapper;
import com.kerrykidz.membership.dao.mapper.CusMemClassEntityMapper;
import com.kerrykidz.membership.dao.model.CusMemClassEntity;
import com.kerrykidz.system.service.ICusMemClassService;
import com.kerrykidz.system.util.FileUtil;
import com.kerrykidz.system.util.JXLSUtil;
import com.kerrykidz.system.vo.CourseSignVo;
import com.rdp.framework.exception.RDPException;

@Service
public class CusMemClassServiceImpl implements ICusMemClassService {
	
	@Autowired
	private CusMemClassEntityMapper cusMemClassEntityMapper;
	
	@Autowired
	private CusClassImpDtlEntityMapper cusClassImpDtlEntityMapper;
	
	/**
	 * 课程签到查询
	 * 
	 * @param 
	 *            
	 * @return
	 * @throws RDPException
	 */
	@Override
	public CusMemClassEntity findClassDetail(CusMemClassEntity entity)
			throws RDPException {
		entity.setIspaging(true);
		List<CusMemClassEntity> beanList = cusMemClassEntityMapper.findClassDetail(entity);
		if(beanList.size()>0){
			entity.setResults(beanList);
		}
		return entity;
	}

	/**
	 * 学生姓名，课程名下拉框
	 * 
	 * @param 
	 *            
	 * @return
	 * @throws RDPException
	 */
	@Override
	public List<CusMemClassEntity> select(@Param("fkBranId") String fkBranId) throws RDPException {
		return cusMemClassEntityMapper.select(fkBranId);
	}

	@Override
	public void saveEntity(CusMemClassEntity entity) throws RDPException {
		cusMemClassEntityMapper.saveEntity(entity);
	}

	public List<CusMemClassEntity> findAllMemClass(String fkBranId, List<String> memberIdList) throws RDPException {
	List<CusMemClassEntity> list= cusMemClassEntityMapper.findAllMemClass(fkBranId, memberIdList);
	return list;
	}

	/**
	 * 
	 * 课程签到导出
	 * @param: @throws RDPException
	 * @return: CusMemClassServiceImpl
	 * @throws
	 */
	@Override
	public boolean courseSignExport(String courseId,String courseName,String branId,HttpServletResponse response) throws RDPException {
			CourseSignVo csv = new CourseSignVo();
			csv.setCourseId(courseId);
			csv.setCourseName(courseName);
			List<CusMemClassEntity> list = cusMemClassEntityMapper.findMemByCourse(courseId,branId);
			csv.setList(list);
			Map<String,Object> beans = new HashMap<String,Object>();
			beans.put("courseSign", csv);
			String destFile = JXLSUtil.exportExcel("courseSignExport", beans);
			try {
				FileUtil.downLoadFile(destFile, response);
			} catch (Exception e) {
				return false;
			}
			return true;
	}		
}
